package com.sofar.mybatisplus.service.impl;

import com.baomidou.dynamic.datasource.annotation.DS;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.sofar.mybatisplus.entity.TblUser;
import com.sofar.mybatisplus.mapper.TblUserMapper;
import com.sofar.mybatisplus.service.TblUserService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;

/**
 * (TblUser)表服务实现类
 *
 * @author makejava
 * @since 2022-08-31 09:05:50
 */
@Service("tblUserService")
public class TblUserServiceImpl extends ServiceImpl<TblUserMapper,TblUser> implements TblUserService {

    @Resource
    private TblUserMapper tblUserMapper;

    @Override
    @DS("master")
    public IPage<TblUser> queryByPage(TblUser tblUser, IPage<TblUser> iPage) {
        IPage<TblUser> tblUsers = tblUserMapper.queryAllByPage(tblUser, iPage);
        return tblUsers;
    }

    @DS("slave_1")
    @Override
    public TblUser queryById(Long id) {
        return this.getById(id);
    }

    @Override
    public boolean addUser(TblUser tblUser) {
        int user = tblUserMapper.insertUser(tblUser);
        return user > 0 ? true : false;
    }

    @Override
    public boolean editUser(TblUser tblUser) {
        int update = tblUserMapper.updateById(tblUser);
//        int user = tblUserMapper.update(tblUser);
        return update > 0 ? true : false;
    }
}
